android versions

Biggs' Apps

for Android devices

  • android home
  • apps
  • testing
  • rants (main)
  • about biggs
  • crossroads

More Kotlin Complaints & Revelations

After a Long Break

Notes on kotlin continued


April 22, 2024

It's been a while

I have been working professionally in kotlin for over three years now. I've learned a lot, and I still need to learn more. It's a very big language and consequently very hard to grok. I still need a space to vent--it's not what I would call a good language by any stretch.

Multi-dimensional Data Structures

Yes, I WILL do something on all the different types of lists, arrays, arraylists, etc. in the future (how about calling it, "ArrayLists, Arrays, and Lists, Oh My!") But right now I want to talk about my current gripe: multi-dimensional data structures. Be they arrays, lists, or that weird hybrid arraylists (and we won't even get into sets and maps!), there is no easy way to implement multi-dimensional data structures.

Let's stick with arrays for simplicity. You can have an array (a 1-dimensional object). And you can have arrays of arrays (sort of a 2-dimensional object). You can continue this for as long as you like, which kinda-sorta work like multi-dimensional objects. But in reality, these are not multi-dimensional objects. They are nested 1-dimensional arrays. The types are different. The behavior is different. And worst of all: very awkward to use.

I thought the big selling point of kotlin was that it was "easier to read" and "less boilerplate". Ha! Big fail here. Note the following comparisons of 2-dimensional arrays:

java C kotlin
initializing
int[][] twoD = new int[10][20]; int two_d[10][20]; val twoD = Array(10) { Array(20) })
accessing top left element
int item = twoD[0][0]; int item = two_d[0][0]; val firstColumn = twoD.get(0) val item = firstColumn.get(0)
writing bottom right element
twoD[9][19] = 5; two_d[9][19] = 5; val lastColumn = twoD.get(9) lastColumn[19] = 5

The big problem is that accessing the elements is awkward (at best) because they are not homogeneous. The first dimension accesses an array. The second dimension accesses the data type. This leads to long and very confusing code that is rife with potential errors.

And all I want to do was make a grid and access the elements. Should be easy, but...sigh.


"Android Evolution" created by Manu Cornet, http://www.bonkersworld.net. All else is copyright 2024 by Scott M. Biggs and Sleep Furiously Productions. Not that that means much these days.